package com.test.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.test.model.UserModel;
import com.test.model.WriteModel;
import com.test.model.ZtreeNodes;

import groovy.time.BaseDuration.From;

public interface UserDao {
	@Select("select name from user where id=1")
	public String getUserId();
	@Insert("insert into user value(#{id},#{name})")
	public void insert(@Param("id")String id, @Param("name")String name);
	@Select("select m.* from menue m inner join role_menue r on m.id=r.menue_id and r.role_id=#{role} and m.state='1'")
	@Results(
			value={
			@Result(column="id",property="id"),
			@Result(column="pid",property="pid"),
			@Result(column="name",property="name"),
			@Result(column="ispoen",property="open"),
			@Result(column="url",property="url")
			}
			)
	public List<ZtreeNodes> getztree(@Param("role")String currentRole);
	@Select("select * from user where account=#{loginName} and password=#{password}")
	public UserModel findUser(@Param("loginName")String loginName, @Param("password")String password);
	@Select("select * from user")
	@Results(value={
			@Result(column="name",property="name"),
			@Result(column="password",property="password"),
			@Result(column="account",property="account")
	})
	public List<WriteModel> getAllUser();
	@Insert("insert into user values(#{id},#{name},#{account},#{password},'0',#{school},#{college},#{clas},#{major},#{role},null)")
	public void add(UserModel user);
	@Select("select count(*) from user where state='1'")
	public int getAccount();
	@Update("update user set state=#{state} where account = #{account}")
	public void updateState(@Param("account")String loginName,@Param("state")String state);
	@Select("select name,account,school,college,clas,major,password from user where state = '1'")
	public List<WriteModel> getonlineUser();
	@Delete("delete from user where account=#{account}")
	public void delete(@Param("account")String account);
	@Select("select * from user where account =#{account}")
	public UserModel getUserByAccount(@Param("account")String account);
	@Update("update user set name = #{name},account=#{account},college=#{college},school=#{school},clas=#{clas},role=#{role} where account=#{account}")
	public void update(UserModel userModel);
	@Select("select * from role where state = '1'")
	public List<Map<String, Object>> getAllRole();
	@Insert("insert into role_menue values (#{id},#{role},#{menu}) ")
	public void prov(@Param("id")String id ,@Param("menu")String menu, @Param("role")String role);
	@Select("select * from menue where state='1'")
	public List<ZtreeNodes> getztreeProv();
	@Delete("delete from role_menue where role_id=#{role}")
	public void deleteallProv(String role);
	@Select("select menue_id from role_menue where role_id=#{role}")
	public List<String> proveShow(String role);
	@Update("update user set imgpath = #{imgpath} where id = #{userId}")
	public void setImage(@Param("imgpath")String imgpath, @Param("userId")String userId);
}
